package com.douqu.game.core.factory;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bean.core.pay.alipay.AlipayConfig;
import com.bean.core.pay.tenpay.bean.TenpayConfig;
import com.bean.core.util.*;
import com.douqu.game.core.i.IPlatform;
import com.douqu.game.core.platform.PlatformQuick;
import com.douqu.game.core.platform.PlatformQuickSDK;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.util.CoreUtils;
import com.douqu.game.core.util.DesUtils;
import com.douqu.game.core.util.LogUtils;
import com.douqu.game.core.util.StringUtils;
import com.douqu.game.core.yjsdk.utils.HTTPHelper;

import java.io.IOException;
import java.net.URLEncoder;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2018-04-04 11:26
 */
public class PlatformFactory {

    public final static String CONFIG_PATH = "data";

    public final static String IOS = "IOS";
    public final static String ANDROID = "ANDROID";
    public static String SYSTEM_VERSION;

    /** 腾讯资源服务器APP_ID */
    public static long TENCENT_COS_APP_ID;
    /** 腾讯资源服务器SECRET_ID */
    public static String TENCENT_COS_SECRET_ID;
    /** 腾讯资源服务器SECRET_KEY */
    public static String TENCENT_COS_SECRET_KEY;
    /** 腾讯资源服务器BUCKET */
    public static String TENCENT_COS_BUCKET;
    /** 腾讯资源服务器地区 */
    public static String TENCENT_COS_REGION;

    /** 即时短信签名头 */
    public static String PHONE_MESSAGE_SIGN;
    /** 即时短信内容'　ex:&phone=1&message=1 */
    public static String PHONE_MESSAGE_CONTENT;
    /** 即时短信发送URL */
    public static String PHONE_MESSAGE_URL;
    /** 验证码短信内容 */
    public static String PHONE_MESSAGE_CAPTCHA;

    /** 微信获取用户信息接口 */
    public static String WECHAT_USERINFO_URL;
    /** QQ获取用户信息接口 */
    public static String QQ_USERINFO_URL;

    /////////////////////////////////////////////////////////////////////////
    /** 小米平台验证session接口 */
    public static String XIAOMI_VERIFY_URL;
    public static String XIAOMI_APP_ID;
    public static String XIAOMI_APP_SECRET;
    /////////////////////////////////////////////////////////////////////////

    /////////////////////////////////////////////////////////////////////////
    /** 易接的参数 */
    public static String YJ_PRIVATE_KEY;
    public static String YJ_CHECK_LOGIN_URL;
    /////////////////////////////////////////////////////////////////////////

    /////////////////////////////////////////////////////////////////////////
    /** 官方百度 激活callback_url */
    public static String BAIDU_CALLBACK_URL;
    /** 百度akey */
    public static String BAIDU_AKEY;
    /////////////////////////////////////////////////////////////////////////

    /////////////////////////////////////////////////////////////////////////
    /**抢玩的参数**/
    public static String QW_CHECK_LOGIN_URL;
    /** 抢玩家验证的key */
    public static String QW_CHECK_PAY_KEY;
    /////////////////////////////////////////////////////////////////////////

    /////////////////////////////////////////////////////////////////////////
    /**即拓的参数**/
    public static String JT_CHECK_LOGIN_URL;
    /** 即拓加密密钥 */
    public static String JT_AKEY;
    /////////////////////////////////////////////////////////////////////////

    /////////////////////////////////////////////////////////////////////////
    /**平平的参数**/
    public static String PP_CHECK_LOGIN_URL;
    /**游戏秘钥**/
    public static String PP_GAME_KEY;
    /**游戏id**/
    public static String PP_GAME_ID;
    public static String PP_PAY_KEY;
//    public static String PP_CHECK_LOGIN_URL_PARAM;
    /////////////////////////////////////////////////////////////////////////

    /////////////////////////////////////////////////////////////////////////
    /** QUICKSDK */
    public static String QUICKSDK_CHECK_LOGIN_URL;
    public static String QUICKSDK_PRODUCT_CODE;
    public static String QUICKSDK_PRODUCT_KEY;
    public static String QUICKSDK_CALLBACK_KEY;
    public static String QUICKSDK_MD5_KEY;
    /////////////////////////////////////////////////////////////////////////

    private static Map<String, IPlatform> platformMap = new HashMap();

    static {
        platformMap.put(SGCommonProto.E_CHANNEL_TYPE.CHANNEL_TYPE_QUICK.name(), new PlatformQuick());
        platformMap.put(SGCommonProto.E_CHANNEL_TYPE.CHANNEL_TYPE_QUICKSDK.name(), new PlatformQuickSDK());
    }

    public static void init(JSONObject jsonObject)
    {
        PlatformFactory.SYSTEM_VERSION = jsonObject.getString("SYSTEM_VERSION");

        PlatformFactory.TENCENT_COS_APP_ID = jsonObject.getLong("TENCENT_COS_APP_ID");
        PlatformFactory.TENCENT_COS_SECRET_ID = jsonObject.getString("TENCENT_COS_SECRET_ID");
        PlatformFactory.TENCENT_COS_SECRET_KEY = jsonObject.getString("TENCENT_COS_SECRET_KEY");
        PlatformFactory.TENCENT_COS_BUCKET = jsonObject.getString("TENCENT_COS_BUCKET");
        PlatformFactory.TENCENT_COS_REGION = jsonObject.getString("TENCENT_COS_REGION");

        PlatformFactory.WECHAT_USERINFO_URL = jsonObject.getString("WECHAT_USERINFO_URL");
        PlatformFactory.QQ_USERINFO_URL = jsonObject.getString("QQ_USERINFO_URL");

//        PlatformFactory.XIAOMI_VERIFY_URL = jsonObject.getString("XIAOMI_VERIFY_URL");
//        PlatformFactory.XIAOMI_APP_ID = jsonObject.getString("XIAOMI_APP_ID");
//        PlatformFactory.XIAOMI_APP_SECRET = jsonObject.getString("XIAOMI_APP_SECRET");
//
//        PlatformFactory.YJ_PRIVATE_KEY = jsonObject.getString("YJ_PRIVATE_KEY");
//        PlatformFactory.YJ_CHECK_LOGIN_URL = jsonObject.getString("YJ_CHECK_LOGIN_URL");
//
//        PlatformFactory.BAIDU_CALLBACK_URL = jsonObject.getString("BAIDU_CALLBACK_URL");
//        PlatformFactory.BAIDU_AKEY = jsonObject.getString("BAIDU_AKEY");
//
//        PlatformFactory.QW_CHECK_LOGIN_URL = jsonObject.getString("QW_CHECK_LOGIN_URL");
//        PlatformFactory.QW_CHECK_PAY_KEY = jsonObject.getString("QW_CHECK_PAY_KEY");
//
//        PlatformFactory.JT_CHECK_LOGIN_URL = jsonObject.getString("JT_CHECK_LOGIN_URL");
//        PlatformFactory.JT_AKEY = jsonObject.getString("JT_AKEY");
//
//        PlatformFactory.PP_CHECK_LOGIN_URL = jsonObject.getString("PP_CHECK_LOGIN_URL");
//        PlatformFactory.PP_GAME_KEY = jsonObject.getString("PP_GAME_KEY");
//        PlatformFactory.PP_GAME_ID = jsonObject.getString("PP_GAME_ID");
//        PlatformFactory.PP_PAY_KEY = jsonObject.getString("PP_PAY_KEY");

        PlatformFactory.QUICKSDK_CHECK_LOGIN_URL = jsonObject.getString("QUICKSDK_CHECK_LOGIN_URL");
        PlatformFactory.QUICKSDK_PRODUCT_CODE = jsonObject.getString("QUICKSDK_PRODUCT_CODE");
        PlatformFactory.QUICKSDK_PRODUCT_KEY = jsonObject.getString("QUICKSDK_PRODUCT_KEY");
        PlatformFactory.QUICKSDK_CALLBACK_KEY = jsonObject.getString("QUICKSDK_CALLBACK_KEY");
        PlatformFactory.QUICKSDK_MD5_KEY = jsonObject.getString("QUICKSDK_MD5_KEY");
    }


    public static void init(Properties properties)
    {
        PlatformFactory.SYSTEM_VERSION = properties.getProperty("SYSTEM_VERSION");

        PlatformFactory.TENCENT_COS_APP_ID = Long.parseLong(properties.getProperty("TENCENT_COS_APP_ID"));
        PlatformFactory.TENCENT_COS_SECRET_ID = properties.getProperty("TENCENT_COS_SECRET_ID");
        PlatformFactory.TENCENT_COS_SECRET_KEY = properties.getProperty("TENCENT_COS_SECRET_KEY");
        PlatformFactory.TENCENT_COS_BUCKET = properties.getProperty("TENCENT_COS_BUCKET");
        PlatformFactory.TENCENT_COS_REGION = properties.getProperty("TENCENT_COS_REGION");

        PlatformFactory.WECHAT_USERINFO_URL = properties.getProperty("WECHAT_USERINFO_URL");
        PlatformFactory.QQ_USERINFO_URL = properties.getProperty("QQ_USERINFO_URL");

//        PlatformFactory.XIAOMI_VERIFY_URL = properties.getProperty("XIAOMI_VERIFY_URL");
//        PlatformFactory.XIAOMI_APP_ID = properties.getProperty("XIAOMI_APP_ID");
//        PlatformFactory.XIAOMI_APP_SECRET = properties.getProperty("XIAOMI_APP_SECRET");
//
//        PlatformFactory.YJ_PRIVATE_KEY = properties.getProperty("YJ_PRIVATE_KEY");
//        PlatformFactory.YJ_CHECK_LOGIN_URL = properties.getProperty("YJ_CHECK_LOGIN_URL");
//
//        PlatformFactory.BAIDU_CALLBACK_URL = properties.getProperty("BAIDU_CALLBACK_URL");
//        PlatformFactory.BAIDU_AKEY = properties.getProperty("BAIDU_AKEY");
//
//        PlatformFactory.QW_CHECK_LOGIN_URL = properties.getProperty("QW_CHECK_LOGIN_URL");
//        PlatformFactory.QW_CHECK_PAY_KEY = properties.getProperty("QW_CHECK_PAY_KEY");
//
//        PlatformFactory.JT_CHECK_LOGIN_URL = properties.getProperty("JT_CHECK_LOGIN_URL");
//        PlatformFactory.JT_AKEY = properties.getProperty("JT_AKEY");
//
//        PlatformFactory.PP_CHECK_LOGIN_URL = properties.getProperty("PP_CHECK_LOGIN_URL");
//        PlatformFactory.PP_GAME_KEY = properties.getProperty("PP_GAME_KEY");
//        PlatformFactory.PP_GAME_ID = properties.getProperty("PP_GAME_ID");
//        PlatformFactory.PP_PAY_KEY = properties.getProperty("PP_PAY_KEY");

        PlatformFactory.QUICKSDK_CHECK_LOGIN_URL = properties.getProperty("QUICKSDK_CHECK_LOGIN_URL");
        PlatformFactory.QUICKSDK_PRODUCT_CODE = properties.getProperty("QUICKSDK_PRODUCT_CODE");
        PlatformFactory.QUICKSDK_PRODUCT_KEY = properties.getProperty("QUICKSDK_PRODUCT_KEY");
        PlatformFactory.QUICKSDK_CALLBACK_KEY = properties.getProperty("QUICKSDK_CALLBACK_KEY");
        PlatformFactory.QUICKSDK_MD5_KEY = properties.getProperty("QUICKSDK_MD5_KEY");

        PlatformFactory.PHONE_MESSAGE_SIGN = properties.getProperty("PHONE_MESSAGE_SIGN");
        PlatformFactory.PHONE_MESSAGE_CONTENT = properties.getProperty("PHONE_MESSAGE_CONTENT");
        PlatformFactory.PHONE_MESSAGE_URL = properties.getProperty("PHONE_MESSAGE_URL");
        PlatformFactory.PHONE_MESSAGE_CAPTCHA = properties.getProperty("PHONE_MESSAGE_CAPTCHA");
    }

    public static void showInfo(boolean showSMS)
    {
        LogUtils.info("SYSTEM_VERSION------------【" + PlatformFactory.SYSTEM_VERSION + "】");

        LogUtils.info("TENCENT_COS_APP_ID--------【" + PlatformFactory.TENCENT_COS_APP_ID + "】");
        LogUtils.info("TENCENT_COS_SECRET_ID-----【" + PlatformFactory.TENCENT_COS_SECRET_ID + "】");
        LogUtils.info("TENCENT_COS_SECRET_KEY----【" + PlatformFactory.TENCENT_COS_SECRET_KEY + "】");
        LogUtils.info("TENCENT_COS_BUCKET--------【" + PlatformFactory.TENCENT_COS_BUCKET + "】");
        LogUtils.info("TENCENT_COS_REGION--------【" + PlatformFactory.TENCENT_COS_REGION + "】");

        LogUtils.info("WECHAT_USERINFO_URL-------【" + PlatformFactory.WECHAT_USERINFO_URL + "】");
        LogUtils.info("QQ_USERINFO_URL-----------【" + PlatformFactory.QQ_USERINFO_URL + "】");

//        LogUtils.info("XIAOMI_VERIFY_URL---------【" + PlatformFactory.XIAOMI_VERIFY_URL + "】");
//        LogUtils.info("XIAOMI_APP_ID-------------【" + PlatformFactory.XIAOMI_APP_ID + "】");
//        LogUtils.info("XIAOMI_APP_SECRET---------【" + PlatformFactory.XIAOMI_APP_SECRET + "】");
//
//        LogUtils.info("YJ_PRIVATE_KEY------------【" + PlatformFactory.YJ_PRIVATE_KEY + "】");
//        LogUtils.info("YJ_CHECK_LOGIN_URL--------【" + PlatformFactory.YJ_CHECK_LOGIN_URL + "】");
//
//        LogUtils.info("BAIDU_CALLBACK_URL--------【" + PlatformFactory.BAIDU_CALLBACK_URL + "】");
//        LogUtils.info("BAIDU_AKEY----------------【" + PlatformFactory.BAIDU_AKEY + "】");
//
//        LogUtils.info("QW_CHECK_LOGIN_URL--------【" + PlatformFactory.QW_CHECK_LOGIN_URL + "】");
//        LogUtils.info("QW_CHECK_PAY_KEY----------【" + PlatformFactory.QW_CHECK_PAY_KEY + "】");
//
//        LogUtils.info("JT_CHECK_LOGIN_URL--------【" + PlatformFactory.JT_CHECK_LOGIN_URL + "】");
//        LogUtils.info("JT_AKEY-------------------【" + PlatformFactory.JT_AKEY + "】");
//        LogUtils.info("PP_CHECK_LOGIN_URL--------【" + PlatformFactory.PP_CHECK_LOGIN_URL + "】");
//        LogUtils.info("PP_GAME_KEY---------------【" + PlatformFactory.PP_GAME_KEY + "】");
//        LogUtils.info("PP_GAME_ID----------------【" + PlatformFactory.PP_GAME_ID + "】");
//        LogUtils.info("PP_PAY_KEY----------------【" + PlatformFactory.PP_PAY_KEY + "】");

        LogUtils.info("QUICKSDK_CHECK_LOGIN_URL--【" + PlatformFactory.QUICKSDK_CHECK_LOGIN_URL + "】");
        LogUtils.info("QUICKSDK_PRODUCT_CODE-----【" + PlatformFactory.QUICKSDK_PRODUCT_CODE + "】");
        LogUtils.info("QUICKSDK_PRODUCT_KEY------【" + PlatformFactory.QUICKSDK_PRODUCT_KEY + "】");
        LogUtils.info("QUICKSDK_CALLBACK_KEY-----【" + PlatformFactory.QUICKSDK_CALLBACK_KEY + "】");
        LogUtils.info("QUICKSDK_MD5_KEY----------【" + PlatformFactory.QUICKSDK_MD5_KEY + "】");

        if(showSMS)
        {
            LogUtils.info("PHONE_MESSAGE_SIGN--------【" + PlatformFactory.PHONE_MESSAGE_SIGN + "】");
            LogUtils.info("PHONE_MESSAGE_CONTENT-----【" + PlatformFactory.PHONE_MESSAGE_CONTENT + "】");
            LogUtils.info("PHONE_MESSAGE_URL---------【" + PlatformFactory.PHONE_MESSAGE_URL + "】");
            LogUtils.info("PHONE_MESSAGE_CAPTCHA-----【" + PlatformFactory.PHONE_MESSAGE_CAPTCHA + "】");
        }

    }


    public final static String KEY_TENPAY = "tenpayConfig";

    public final static String KEY_ALIPAY = "alipayConfig";

    public final static String KEY_OTHER = "otherConfig";



    private static JSONObject createConfig(String configName, String configValue, boolean hideDetail)
    {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("configName", configName);
        if(hideDetail && !Utils.isNullOrEmpty(configValue) && configValue.length() > 12)
        {
            configValue = configValue.substring(0, 6) + "......" + configValue.substring(configValue.length()-6, configValue.length());
        }
        jsonObject.put("configValue", configValue);
        return jsonObject;
    }

    public static JSONArray getTenpayConfig()
    {
        JSONArray result = new JSONArray();
        result.add(createConfig("appid", TenpayConfig.appid, false));
        result.add(createConfig("mch_id", TenpayConfig.mch_id, false));
        result.add(createConfig("app_secret", TenpayConfig.app_secret, true));
        result.add(createConfig("key", TenpayConfig.key, true));
        result.add(createConfig("trade_type", TenpayConfig.trade_type, false));
        result.add(createConfig("package_str", TenpayConfig.package_str, false));
        result.add(createConfig("device_info", TenpayConfig.device_info, false));
        result.add(createConfig("sign_type", TenpayConfig.sign_type, false));
        result.add(createConfig("notify_url", TenpayConfig.notify_url, false));
        result.add(createConfig("get_openid_url", TenpayConfig.get_openid_url, false));
        result.add(createConfig("create_trade_url", TenpayConfig.create_trade_url, false));
        result.add(createConfig("query_trade_url", TenpayConfig.query_trade_url, false));
        return result;
    }

    public static JSONArray getAlipayConfig()
    {
        JSONArray result = new JSONArray();
        result.add(createConfig("appid", AlipayConfig.appid, false));
        result.add(createConfig("private_key", AlipayConfig.private_key, true));
        result.add(createConfig("ali_public_key", AlipayConfig.ali_public_key, true));
        result.add(createConfig("key", AlipayConfig.key, true));
        result.add(createConfig("seller_id", AlipayConfig.seller_id, false));
        result.add(createConfig("partner", AlipayConfig.partner, false));
        result.add(createConfig("email", AlipayConfig.email, false));
        result.add(createConfig("account_name", AlipayConfig.account_name, false));
        result.add(createConfig("sign_type", AlipayConfig.sign_type, false));
        result.add(createConfig("log_path", AlipayConfig.log_path, false));
        result.add(createConfig("notify_url", AlipayConfig.notify_url, false));
        result.add(createConfig("create_trade_url", AlipayConfig.create_trade_url, false));
        return result;
    }

    public static JSONArray getOtherConfig()
    {
        JSONArray result = new JSONArray();
        result.add(createConfig("SYSTEM_VERSION", PlatformFactory.SYSTEM_VERSION + "", false));
        result.add(createConfig("TENCENT_COS_APP_ID", PlatformFactory.TENCENT_COS_APP_ID + "", false));
        result.add(createConfig("TENCENT_COS_SECRET_ID", PlatformFactory.TENCENT_COS_SECRET_ID, false));
        result.add(createConfig("TENCENT_COS_SECRET_KEY", PlatformFactory.TENCENT_COS_SECRET_KEY, true));
        result.add(createConfig("TENCENT_COS_BUCKET", PlatformFactory.TENCENT_COS_BUCKET, false));
        result.add(createConfig("TENCENT_COS_REGION", PlatformFactory.TENCENT_COS_REGION, false));
        result.add(createConfig("WECHAT_USERINFO_URL", PlatformFactory.WECHAT_USERINFO_URL, false));
        result.add(createConfig("QQ_USERINFO_URL", PlatformFactory.QQ_USERINFO_URL, false));
        result.add(createConfig("XIAOMI_VERIFY_URL", PlatformFactory.XIAOMI_VERIFY_URL, false));
        result.add(createConfig("XIAOMI_APP_ID", PlatformFactory.XIAOMI_APP_ID, false));
        result.add(createConfig("XIAOMI_APP_SECRET", PlatformFactory.XIAOMI_APP_SECRET, true));
        result.add(createConfig("YJ_PRIVATE_KEY", PlatformFactory.YJ_PRIVATE_KEY, true));
        result.add(createConfig("YJ_CHECK_LOGIN_URL", PlatformFactory.YJ_CHECK_LOGIN_URL, false));
        result.add(createConfig("BAIDU_CALLBACK_URL", PlatformFactory.BAIDU_CALLBACK_URL, false));
        result.add(createConfig("BAIDU_AKEY", PlatformFactory.BAIDU_AKEY, true));
        result.add(createConfig("QW_CHECK_LOGIN_URL", PlatformFactory.QW_CHECK_LOGIN_URL, false));
        result.add(createConfig("QW_CHECK_PAY_KEY",PlatformFactory.QW_CHECK_PAY_KEY, false));
        result.add(createConfig("JT_AKEY", PlatformFactory.JT_AKEY, true));
        result.add(createConfig("JT_CHECK_LOGIN_URL", PlatformFactory.JT_CHECK_LOGIN_URL, false));
        result.add(createConfig("PP_CHECK_LOGIN_URL", PlatformFactory.PP_CHECK_LOGIN_URL, false));
//        result.add(createConfig("PP_CHECK_LOGIN_URL_PARAM", PlatformFactory.PP_CHECK_LOGIN_URL_PARAM, false));
        result.add(createConfig("PP_GAME_KEY", PlatformFactory.PP_GAME_KEY, true));
        result.add(createConfig("PP_GAME_ID", PlatformFactory.PP_GAME_ID, false));
        result.add(createConfig("PP_PAY_KEY", PlatformFactory.PP_PAY_KEY, true));
        result.add(createConfig("QUICKSDK_CHECK_LOGIN_URL", PlatformFactory.QUICKSDK_CHECK_LOGIN_URL, false));
        result.add(createConfig("QUICKSDK_PRODUCT_CODE", PlatformFactory.QUICKSDK_PRODUCT_CODE, false));
        result.add(createConfig("QUICKSDK_PRODUCT_KEY", PlatformFactory.QUICKSDK_PRODUCT_KEY, false));
        result.add(createConfig("QUICKSDK_CALLBACK_KEY", PlatformFactory.QUICKSDK_CALLBACK_KEY, false));
        result.add(createConfig("QUICKSDK_MD5_KEY", PlatformFactory.QUICKSDK_MD5_KEY, false));
        return result;
    }

    public static JSONObject alipayConfigToJSON()
    {
        JSONObject alipayJson = new JSONObject();
        alipayJson.put("appid", AlipayConfig.appid);
        alipayJson.put("private_key", AlipayConfig.private_key);
        alipayJson.put("ali_public_key", AlipayConfig.ali_public_key);
        alipayJson.put("key", AlipayConfig.key);
        alipayJson.put("seller_id", AlipayConfig.seller_id);
        alipayJson.put("partner", AlipayConfig.partner);
        alipayJson.put("email", AlipayConfig.email);
        alipayJson.put("account_name", AlipayConfig.account_name);
        alipayJson.put("sign_type", AlipayConfig.sign_type);
        alipayJson.put("log_path", AlipayConfig.log_path);
        alipayJson.put("notify_url", AlipayConfig.notify_url);
        alipayJson.put("create_trade_url", AlipayConfig.create_trade_url);
        return alipayJson;
    }

    public static JSONObject tenpayConfigToJSON()
    {
        JSONObject tenpayJson = new JSONObject();
        tenpayJson.put("appid", TenpayConfig.appid);
        tenpayJson.put("mch_id", TenpayConfig.mch_id);
        tenpayJson.put("app_secret", TenpayConfig.app_secret);
        tenpayJson.put("key", TenpayConfig.key);
        tenpayJson.put("trade_type", TenpayConfig.trade_type);
        tenpayJson.put("package_str", TenpayConfig.package_str);
        tenpayJson.put("device_info", TenpayConfig.device_info);
        tenpayJson.put("sign_type", TenpayConfig.sign_type);
        tenpayJson.put("notify_url", TenpayConfig.notify_url);
        tenpayJson.put("get_openid_url", TenpayConfig.get_openid_url);
        tenpayJson.put("create_trade_url", TenpayConfig.create_trade_url);
        tenpayJson.put("query_trade_url", TenpayConfig.query_trade_url);
        return tenpayJson;
    }

    public static JSONObject otherConfigToJSON()
    {
        JSONObject otherJson = new JSONObject();
        otherJson.put("SYSTEM_VERSION", PlatformFactory.SYSTEM_VERSION);
        otherJson.put("TENCENT_COS_APP_ID", PlatformFactory.TENCENT_COS_APP_ID);
        otherJson.put("TENCENT_COS_SECRET_ID", PlatformFactory.TENCENT_COS_SECRET_ID);
        otherJson.put("TENCENT_COS_SECRET_KEY", PlatformFactory.TENCENT_COS_SECRET_KEY);
        otherJson.put("TENCENT_COS_BUCKET", PlatformFactory.TENCENT_COS_BUCKET);
        otherJson.put("TENCENT_COS_REGION", PlatformFactory.TENCENT_COS_REGION);
        otherJson.put("WECHAT_USERINFO_URL", PlatformFactory.WECHAT_USERINFO_URL);
        otherJson.put("QQ_USERINFO_URL", PlatformFactory.QQ_USERINFO_URL);
        otherJson.put("XIAOMI_VERIFY_URL", PlatformFactory.XIAOMI_VERIFY_URL);
        otherJson.put("XIAOMI_APP_ID", PlatformFactory.XIAOMI_APP_ID);
        otherJson.put("XIAOMI_APP_SECRET", PlatformFactory.XIAOMI_APP_SECRET);
        otherJson.put("YJ_PRIVATE_KEY", PlatformFactory.YJ_PRIVATE_KEY);
        otherJson.put("YJ_CHECK_LOGIN_URL", PlatformFactory.YJ_CHECK_LOGIN_URL);
        otherJson.put("BAIDU_CALLBACK_URL", PlatformFactory.BAIDU_CALLBACK_URL);
        otherJson.put("BAIDU_AKEY", PlatformFactory.BAIDU_AKEY);
        otherJson.put("QW_CHECK_LOGIN_URL", PlatformFactory.QW_CHECK_LOGIN_URL);
        otherJson.put("QW_CHECK_PAY_KEY", PlatformFactory.QW_CHECK_PAY_KEY);
        otherJson.put("JT_CHECK_LOGIN_URL", PlatformFactory.JT_CHECK_LOGIN_URL);
        otherJson.put("JT_AKEY", PlatformFactory.JT_AKEY);
        otherJson.put("PP_CHECK_LOGIN_URL", PlatformFactory.PP_CHECK_LOGIN_URL);
//        otherJson.put("PP_CHECK_LOGIN_URL_PARAM", PlatformFactory.PP_CHECK_LOGIN_URL_PARAM);
        otherJson.put("PP_GAME_KEY", PlatformFactory.PP_GAME_KEY);
        otherJson.put("PP_GAME_ID", PlatformFactory.PP_GAME_ID);
        otherJson.put("PP_PAY_KEY", PlatformFactory.PP_PAY_KEY);
        otherJson.put("QUICKSDK_CHECK_LOGIN_URL", PlatformFactory.QUICKSDK_CHECK_LOGIN_URL);
        otherJson.put("QUICKSDK_PRODUCT_CODE", PlatformFactory.QUICKSDK_PRODUCT_CODE);
        otherJson.put("QUICKSDK_PRODUCT_KEY", PlatformFactory.QUICKSDK_PRODUCT_KEY);
        otherJson.put("QUICKSDK_CALLBACK_KEY", PlatformFactory.QUICKSDK_CALLBACK_KEY);
        otherJson.put("QUICKSDK_MD5_KEY", PlatformFactory.QUICKSDK_MD5_KEY);
        return otherJson;
    }



    public static String auth(SGCommonProto.E_CHANNEL_TYPE channelType, String account, String password)
    {
        LogUtils.info("认证,渠道:" + channelType + ", account:" + account + ", password:" + password);

        IPlatform platform = platformMap.get(channelType.name());
        if(platform == null)
        {
            LogUtils.error("暂时还没有此渠道认证-> " + channelType);
            return null;
        }
        return platform.auth(account, password);

//        if(channelType == SGCommonProto.E_CHANNEL_TYPE.CHANNEL_TYPE_QIANGWAN)
//        {
//            String url = MessageFormat.format(PlatformFactory.QW_CHECK_LOGIN_URL, account, password);
//            LogUtils.info("抢玩url:" + url );
//            JSONObject result = null;
//            int status = 0;
//            String msg = "";
//            try {
//                result = HttpJsonUtils.httpGet(url);
//                status =  result.getInteger("status");
//                msg = result.getString("msg");
//                LogUtils.info("抢玩返回值:" + status + "  " + msg);
//            }catch (Exception e){
//                LogUtils.error("WQ获取数据失败:" + account);
//                e.printStackTrace();
//                LogUtils.errorException(e);
//                return null;
//            }
//            if(StringUtils.isNullOrEmpty(msg) || status == 0 || msg.equals("failed"))
//            {
//                LogUtils.error("抢玩认证失败:" + account);
//                return null;
//            }
//        }
//        else if(channelType == SGCommonProto.E_CHANNEL_TYPE.CHANNEL_TYPE_PINGPING)
//        {
//            String Sign = MD5Utils.encode(PlatformFactory.PP_GAME_ID + "" + account + "" + password + "" + PlatformFactory.PP_GAME_KEY);
//            String url = MessageFormat.format(PlatformFactory.PP_CHECK_LOGIN_URL, PlatformFactory.PP_GAME_ID, account, password, Sign);
//            LogUtils.info("平平url:" + url );
//            JSONObject result = null;
//            int status;
//            String msg;
//            try {
//                result = HttpJsonUtils.httpPost(url);
//                status =  result.getInteger("Status");
//                msg = result.getString("Msg");
//                LogUtils.info("平平返回值:" + status + "  " + msg);
//            }catch (Exception e){
//                LogUtils.error("平平获取数据失败:" + account);
//                LogUtils.errorException(e);
//                return null;
//            }
//            if( StringUtils.isNullOrEmpty(msg) || status != 0)
//            {
//                LogUtils.error("平平获取数据失败:" + account);
//                return null;
//            }
//        }
//        else if(channelType == SGCommonProto.E_CHANNEL_TYPE.CHANNEL_TYPE_JITUO)
//        {
//            String [] param = password.split(ConstantFactory.DIVISION);
//            //版本号默认为1.0
//            String version;
//            //商户名简写
//            String componentCode;
//            //时间戳
//            String timeStamp ;
//            String token ;
//            try {
//                version = param[0];
//                componentCode = param[1];
//                timeStamp = param[2];
//                token = param[3];
//            } catch (Exception e) {
//                LogUtils.error("参数解析错误:" + password);
////                LogUtils.errorException(e);
//                return null;
//            }
//            //认证编号
//            String authenticateCode=version+"|"+componentCode+"|"+timeStamp;
//            //加密
//            String authenticateCodes= DesUtils.encrypt(authenticateCode, PlatformFactory.JT_AKEY);
//            String url = MessageFormat.format(PlatformFactory.JT_CHECK_LOGIN_URL, version, componentCode, timeStamp, authenticateCodes, token);
//            LogUtils.info("即拓url:" + url );
//            String str = HttpStringUtil.sendHttpGet(url);
//            LogUtils.info("即拓str:" + str );
//            JSONObject result = JSONObject.parseObject(str);
//            JSONObject object;
//            //里面包含userId
//            JSONObject data ;
//            String resultCode;
//            String resultMsg;
//            try {
//                object =result.getJSONObject("result");
//                resultCode = object.getString("resultCode");
//                resultMsg = object.getString("resultMsg");
//                data =result.getJSONObject("data");
//                LogUtils.info("即拓返回值:resultCode:" + resultCode + " resultMsg: " + resultMsg + "data: " +data);
//            }catch (Exception e){
//                LogUtils.error("即拓获取数据失败:" + account);
//                LogUtils.errorException(e);
//                return null;
//            }
//            if(!resultCode.equals("000000") || !resultMsg.equals("成功") || data == null || Utils.isNullOrEmpty(data.getString("userid"))){
//                LogUtils.error("即拓验证失败:" + account);
//                return null;
//            }
//
//            account = data.getString("userid");
//            LogUtils.info("JT返回userid -> " + account);
//        }
//        else if(channelType == SGCommonProto.E_CHANNEL_TYPE.CHANNEL_TYPE_YJ)
//        {
//            String [] param = password.split(ConstantFactory.DIVISION);
//            String app = null;
//            String sdk = null;
//            String uin = null;
//            String sess = null;
//            try {
//                app = param[0];
//                sdk = param[1];
//                uin = param[2];
//                sess = param[3];
//            } catch (Exception e) {
//                LogUtils.error("参数解析错误:" + password);
////                LogUtils.errorException(e);
//                return null;
//            }
//
//            try {
//                String url = MessageFormat.format(PlatformFactory.YJ_CHECK_LOGIN_URL, app, sdk, URLEncoder.encode(uin, "UTF-8"), URLEncoder.encode(sess, "UTF-8"));
//
//                HTTPHelper.SimpleHTTPResult ret = HTTPHelper.simpleInvoke ("GET", url, null, null);
//                // 下面的返回值由CP服务器和客户端定义，这里的返回值只做参考用
//                if (ret.code != 200) {
//                    return null;
//                }
//                if (ret.data == null || ret.data.length == 0) {
//                    return null;
//                } else {
//                    String r = new String (ret.data);
//                    Integer i = new Integer(r);
//                    if (i != 0) {
//                        return null;
//                    }
//                }
//            } catch (IOException e) {
//                LogUtils.error("易接验证失败:" + account);
//                LogUtils.errorException(e);
//                return null;
//            }
//        }
//        else if(channelType == SGCommonProto.E_CHANNEL_TYPE.CHANNEL_TYPE_QUICKSDK)
//        {
//            String url = MessageFormat.format(PlatformFactory.QUICKSDK_CHECK_LOGIN_URL, password, PlatformFactory.QUICKSDK_PRODUCT_CODE, account);
//            LogUtils.info("QUICKSDK url -> " + url);
//            String result = HttpStringUtil.sendHttpPost(url);
//            LogUtils.info("QUICKSDK auth result -> " + result);
//            if(!result.equals("1"))
//            {
//                LogUtils.error("QUICKSDK验证用户信息失败:account->" + account + "  password->" + password);
//                return null;
//            }
//        }
//        else if(channelType == SGCommonProto.E_CHANNEL_TYPE.CHANNEL_TYPE_PHONE)
//        {
//            if(!FormatUtils.checkPhoneFormat(account))
//            {
//                LogUtils.debug("手机号码格式错误:" + account);
//                return null;
//            }
//        }
//        else if(channelType == SGCommonProto.E_CHANNEL_TYPE.CHANNEL_TYPE_QQ)
//        {
//            String qqUrl = MessageFormat.format(PlatformFactory.QQ_USERINFO_URL, password, account);
//            String str = HttpStringUtil.sendHttpGet(qqUrl);//https的必须要用这个类的方法，涉及到ssl
//            JSONObject result = JSONObject.parseObject(str);
//            String nickName = "";
//            int gender = 0;
//            String avatar = "";
//            try{
//                nickName = result.getString("nickname");
//                avatar = result.getString("figureurl_qq_2");
//                String genderName = result.getString("gender");
//            }catch (Exception e){
//                LogUtils.error("1QQ获取数据失败:" + account);
//                LogUtils.errorException(e);
//                return null;
//            }
//
//            if(StringUtils.isNullOrEmpty(nickName) || StringUtils.isNullOrEmpty(avatar))
//            {
//                LogUtils.error("2QQ获取数据失败:" + account);
//                return null;
//            }
//        }
//        else if(channelType == SGCommonProto.E_CHANNEL_TYPE.CHANNEL_TYPE_WECHAT)
//        {
//            String wechatUrl = MessageFormat.format(PlatformFactory.WECHAT_USERINFO_URL, password, account);
//            String str = HttpStringUtil.sendHttpGet(wechatUrl);
//            JSONObject result = JSONObject.parseObject(str);
//            /**
//             * openid	普通用户的标识，对当前开发者帐号唯一
//             nickname	普通用户昵称
//             sex	普通用户性别，1为男性，2为女性
//             province	普通用户个人资料填写的省份
//             city	普通用户个人资料填写的城市
//             country	国家，如中国为CN
//             headimgurl	用户头像，最后一个数值代表正方形头像大小（有0、46、64、96、132数值可选，0代表640*640正方形头像），用户没有头像时该项为空
//             privilege	用户特权信息，json数组，如微信沃卡用户为（chinaunicom）
//             unionid	用户统一标识。针对一个微信开放平台帐号下的应用，同一用户的unionid是唯一的。
//             */
//            LogUtils.debug("微信获取数据:" + result);
//            String nickName = "";
//            int gender = 0;
//            String avatar = "";
//            try {
//                nickName = result.getString("nickname");
//                gender = result.getInteger("sex");
//                avatar = result.getString("headimgurl");
//            }catch (Exception e){
//                LogUtils.debug("微信获取数据失败:" + account);
//                return null;
//            }
//
//            if(StringUtils.isNullOrEmpty(nickName) || StringUtils.isNullOrEmpty(avatar))
//            {
//                LogUtils.info("2QQ获取数据失败:" + account);
//                return null;
//            }
//        }
//        else if(channelType == SGCommonProto.E_CHANNEL_TYPE.CHANNEL_TYPE_QUICK)
//        {
//            //这里不需要处理
//        }
//        else
//        {
//            LogUtils.error("暂时还没有此渠道认证-> " + channelType);
//        }
//
//        return CoreUtils.createAccount(account, channelType);
    }





}
